import QtQuick
import QtQuick.Controls
import Qt.labs.platform as Platform // 解决命令冲突
import QtQuick.Layouts

ApplicationWindow {
    width: 640
    height: 480
    visible: true
    title: qsTr("PC Image Viewer")

    background: Rectangle {
        color: 'darkGray'
    }

    Image {
        id: image
        anchors.fill: parent
        fillMode: Image.PreserveAspectFit
//        source: "images/qq.png" // for test
        asynchronous: true // 异步加载可能更快
    }

    header: ToolBar { // 工具栏
        Flow {
            anchors.fill: parent
            ToolButton {
                text: qsTr("打开")
                icon.source: "images/open"
                onClicked: fileOpenDialog.open()
            }
        }
    }

    Platform.FileDialog {
        id: fileOpenDialog
        title: "选择图片"
        nameFilters: [
            "Image files(*.png *jpg)", "all files(*.*)"
        ]

        onAccepted: {
            image.source = fileOpenDialog.file // final accepted file url
        }
    }

    menuBar: MenuBar {
        Menu {
            title: '&File'
            MenuItem {
                text: "&Open..."
                icon.source: "images/open.png"
                onTriggered: fileOpenDialog.open()
            }
        }

        Menu {
            title: '&Help'
            MenuItem {
                text: "&About..."
                onTriggered: aboutDialog.open()
            }
        }
    }

    Dialog {
        id: aboutDialog
        width: 300; height: 150
        anchors.centerIn: parent
        title: "About"
        Label {
            anchors.fill: parent
            text: "0123456789ABCEFGHIJKLMNOPQRSTUVWXYZ"
            horizontalAlignment: Text.AlignHCenter
        }
        standardButtons: Platform.StandardButton.Ok
    }
}
